﻿
'the server to get requests from clients
Public MustInherit Class detector
    Inherits producer
    Private DETECTOR_QPS As Int64

    Protected MustOverride Sub startImpl(ByVal port As Int32, ByVal connectionCount As Int64)

    Private Overloads Sub start(ByVal port As Int32, ByVal connectionCount As Int64)
        DETECTOR_QPS = counter.registerRateAndLastRate(strcat("DETECTOR_QPS_", port))
        startImpl(port, connectionCount)
    End Sub

    Protected Function invoke(ByVal job As ijob) As eventComb
        assert(Not job Is Nothing)
        counter.increase(DETECTOR_QPS)
        job.receive_lop()
        If job.valid() Then
            Return ijobEventComb(job)
        Else
            Return eventComb.failed()
        End If
    End Function

    Public Shared Shadows Function initial(ByVal name As String,
                                           ByVal config As configParser,
                                           ByVal detector As detector) As Boolean
        assert(Not detector Is Nothing)
        If producer.initial(name, config, detector) Then
            Dim port As Int32 = 0
            Dim connectionCount As Int64 = 0
            If read_port_connectionCount(config, name, port, connectionCount, 128) Then
                detector.start(port, connectionCount)
                Return True
            Else
                Return False
            End If
        Else
            Return False
        End If
    End Function
End Class
